﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FactoryLib.services.Map
{
    /// <summary>
    /// 饿汉式 单例，类加载就初始化到内存
    /// </summary>
    public class Map
    {
        private static Map _instance = new Map();
        private Map()
        {

        }

        public static Map GetInstance()
        {
            return _instance;
        }

        public void InitMap()
        {
            Console.WriteLine("加载王者荣耀地图完成");
        }
    }

    /// <summary>
    /// 双If加锁
    /// </summary>
    public class Map2
    {
        public string _desc = "加载王者荣耀地图完成";

        private static readonly object lockObj = new object();
        private static Map2 _instance;
        private Map2()
        {

        }

        public static Map2 GetInstance()
        {
            if (_instance == null )
            {
                lock (lockObj)
                {
                    if (_instance == null)
                    {
                        _instance = new Map2();
                    }
                    return _instance;
                }
            }
            else
            {
                return _instance;
            }
        }
    }
}
